package com.heima.file.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.heima.file.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Data
@Configuration
@EnableConfigurationProperties({OssConfigProperties.class})
//当引入FileStorageService接口时
@ConditionalOnClass(FileStorageService.class)
public class OssConfig {

    @Autowired
    private OssConfigProperties ossConfigProperties;

    @Bean
    public OSS buildMinioClient() {
        OSS ossClient = new OSSClientBuilder().build(ossConfigProperties.getEndpoint(),
                ossConfigProperties.getAccessKeyId(), ossConfigProperties.getAccessKeySecret());
        return ossClient;
    }
}